[ty] Preserve literal-string origin in comparison narrowing - #27582
Open
carljm wants to merge 1 commit into
Open
[ty] Preserve literal-string origin in comparison narrowing#27582carljm wants to merge 1 commit into
carljm wants to merge 1 commit into
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 96.96%. The percentage of expected errors that received a diagnostic held steady at 92.96%. The number of fully passing files held steady at 106/133. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unsound-return-statement |
0 | 0 | 1 |
| Total | 0 | 0 | 1 |
Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.
Raw diff:
meson (https://github.com/mesonbuild/meson)
- mesonbuild/compilers/mixins/visualstudio.py:392:16 warning[unsound-return-statement] Unsound return statement: `list[str] | list[str | Divergent]` is not a subtype of `list[str]`
+ mesonbuild/compilers/mixins/visualstudio.py:392:16 warning[unsound-return-statement] Unsound return statement: `list[str] | list[Divergent]` is not a subtype of `list[str]`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a consistent view of the semantics of
LiteralStringand stringLiteraltypes. The key observation is that ifLiteral["hello"] <: LiteralString <: strholds, andLiteralStringis not equivalent tostr, that necessarily implies thatLiteral["hello"]does not include all runtime string objects with the value"hello"-- only those that are known to have literal origin (that is, those that also inhabitLiteralString).Similar to
NewTypeand generic specializations, this can be described in terms of typed values having both a runtime object and possibly static-only "tags", which don't exist at runtime but still participate in determining which types they inhabit. So a runtime string object with value"hello"may be a typed value that carries the "literal origin" tag (in this case it inhabitsLiteralStringandLiteral["hello"]), or may not carry that tag (in which case it inhabits neitherLiteralStringnorLiteral["hello"].)This PR just carries this understanding consistently through our narrowing support.
LiteralStringorigin.Closes astral-sh/ty#4214.
Test plan
str & ~LiteralString,str & ~Literal["hello"], and~Literal["hello"]across comparison truthiness and equality/identity narrowing, including reversed operands, inequality branches, optional unions, and strict equality semantics.